﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace MainWinform
{
    /// <summary>
    /// 为无窗口应用创建消息筛选器
    /// </summary>
    public class MsgFilter : IMessageFilter
    {
        protected Dictionary<int, Action<Message>> _MessageActionDict = new Dictionary<int, Action<Message>>();

        public virtual void AddAction(int msgID,Action<Message> action)
        {
            _MessageActionDict.Add(msgID, action);
        }

        public virtual bool PreFilterMessage(ref Message m)
        {

            if(_MessageActionDict.ContainsKey(m.Msg))
            {
                _MessageActionDict[m.Msg](m);
                return true;
            }

            return false;
        }
    }
}
